package com.fingard.dsp.bank.reqrespobj.entrust;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RequestBase;

import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;

/**
 * 纯签约请求实体类
 */
public class ReqEntrust extends RequestBase {
    /** 公众号或开发者应用ID */
    public String appId = "";

    /** 商户ID */
    public String merchantId = "";

    /** 商户账号 */
    public String ownAct = "";

    /** 商品描述 */
    public String description = "";

    /** 订单号 */
    public String rdSeq;

    /** 交易币种 */
    public String cur = "";

    /** 交易金额 */
    public String amount = "";

    /** 商品备注 */
    public String memo = "";

    /** 订单生效时间 */
    public String timeStart = "";

    public Date getTimeStart() throws ParseException {
        return Format.DateTime14Format.parse(timeStart);
    }

    /** 订单失效时间 */
    public String timeExpire = "";

    public Date getTimeExpire() throws ParseException {
        return Format.DateTime14Format.parse(timeExpire);
    }

    /**
     * 获取有效时间 (分钟)
     *
     * @return 有效时间
     * @throws ParseException
     *             日期格式转换异常
     */
    public String getValidTime() throws ParseException {
        String validTime = "";

        long timeOut = getTimeExpire().getTime() - getTimeStart().getTime();
        validTime = String.valueOf(timeOut / 1000 / 60);

        return validTime;
    }

    /** 用户标识,trade_type=JSAPI时（即公众号支付），此参数必传 */
    public String openid = "";

    /** 附加字段 */
    public String attach = "";

    /** 付款人姓名 */
    public String oppActName = "";

    /** 证件类型 */
    public String certType = "";

    /** 付款人证件号码 */
    public String certNumber = "";

    /** 付款人手机号 */
    public String cellPhone = "";

    /** 协议模板id */
    public String planId = "";

    /** 签约协议号 */
    public String authCode = "";

    /** 请求序列号 */
    public String serialNo = "";

    /** 是否实名标志 */
    public String realNameFlag = "";

    /** 终端IP */
    public String createIP = "";

    /** 签约类型(枚举：01-公众号,02-H5,03-扫码,04-APP,05-小程序) */
    public String signType = "";

    /** 保险地区 */
    public String region;

    public ReqEntrust(HashMap<String, String> p_hashMap, ReqRespHeader p_header) throws Exception {
        reqHeader = p_header;
        if (p_hashMap.containsKey("AppId")) {
            appId = p_hashMap.get("AppId");
            if (appId == null) {
                appId = "";
            }
        }
        if (p_hashMap.containsKey("MchId")) {
            merchantId = p_hashMap.get("MchId");
            if (merchantId == null) {
                merchantId = "";
            }
        }
        if (p_hashMap.containsKey("OurBankAccount")) {
            ownAct = p_hashMap.get("OurBankAccount");
            if (ownAct == null) {
                ownAct = "";
            }
        }
        if (p_hashMap.containsKey("Description")) {
            description = p_hashMap.get("Description");
        }
        if (p_hashMap.containsKey("RdSeq")) {
            rdSeq = p_hashMap.get("RdSeq");
        }
        if (p_hashMap.containsKey("Cur")) {
            cur = p_hashMap.get("Cur");
        }
        if (p_hashMap.containsKey("Amount")) {
            amount = p_hashMap.get("Amount");
        }
        if (p_hashMap.containsKey("Memo")) {
            memo = p_hashMap.get("Memo");
        }
        if (p_hashMap.containsKey("TimeStart")) {
            timeStart = p_hashMap.get("TimeStart");
        }
        if (p_hashMap.containsKey("TimeExpire")) {
            timeExpire = p_hashMap.get("TimeExpire");
        }
        if (p_hashMap.containsKey("OpenId")) {
            openid = p_hashMap.get("OpenId");
        }
        if (p_hashMap.containsKey("Attach")) {
            attach = p_hashMap.get("Attach");
        }
        if (p_hashMap.containsKey("OppActName")) {
            oppActName = p_hashMap.get("OppActName");
        }
        if (p_hashMap.containsKey("CertType")) {
            certType = p_hashMap.get("CertType");
        }
        if (p_hashMap.containsKey("CertNumber")) {
            certNumber = p_hashMap.get("CertNumber");
        }
        if (p_hashMap.containsKey("CellPhone")) {
            cellPhone = p_hashMap.get("CellPhone");
        }
        if (p_hashMap.containsKey("PlanID")) {
            planId = p_hashMap.get("PlanID");
        }
        if (p_hashMap.containsKey("ContractCode")) {
            authCode = p_hashMap.get("ContractCode");
        }
        if (p_hashMap.containsKey("RequestSerial")) {
            serialNo = p_hashMap.get("RequestSerial");
        }
        if (p_hashMap.containsKey("RealNameFlag")) {
            realNameFlag = p_hashMap.get("RealNameFlag");
        }
        if (p_hashMap.containsKey("ClientIp")) {
            createIP = p_hashMap.get("ClientIp");
        }
        if (p_hashMap.containsKey("EntrustType")) {
            signType = p_hashMap.get("EntrustType");
        }
        if (p_hashMap.containsKey("Region")) {
            region = p_hashMap.get("Region");
        }
    }
}